|
|
|
|
|
|
|
When an application is launched, the executable is mapped into memory starting from the module address for that executable. Each DLL used by the application is mapped into a different address, which becomes the module address for that DLL.1 The GetModuleFileName function can retrieve the file name for any module used by a process. |
|
|
|
|
|
|
|
|
In this case, we take advantage of a cool trickif you set the hModule parameter to 0, the function retrieves the name of the original application that launched the process. |
|
|
|
|
|
|
|
|
The ExecutableFinder project is a simple ActiveX DLL component that contains a single-class object called Server. This object exposes a single method that allows the caller to determine if the running application is Visual Basic. When an application creates a Server object, the ExecutableFinder DLL is loaded into the process. The IsThisVB method uses the GetModuleFileName function to see if the running executable is Visual Basic. When you are running a program within the Visual Basic development environment, GetModuleFileName will indicate that the program is vb6.exe, vb5.exe, or vb32.exe depending on whether you are running VB6, VB5, or VB4. When you are running a compiled executable, it will retrieve the path of the compiled executable. |
|
|
|
|
|
|
|
|
The Server class contains the following code: |
|
|
|
|
|
|
|
|
' What's the Executable?
' Copyright © 1998 by Desaware Inc. All Rights Reserved
Option Explicit
Private Declare Function GetModuleFileName Lib "kernel32" Alias _
"GetModuleFileNameA" (ByVal hModule As Long, ByVal lpFileName As _
String, ByVal nSize As Long) As Long
Private Const MAX_PATH = 260
Public Function IsThisVB() As Boolean
Dim ExecName As String
Dim LastBackslashPos As Long
ExecName = String$(MAX_PATH + 1, 0)
Call GetModuleFileName(0, ExecName, MAX_PATH)
' Now strip off the path
LastBackslashPos = InStrRev(ExecName, "\")
If LastBackslashPos = 0 Then
LastBackslashPos = InStrRev(ExecName, ":")
End If
ExecName = Mid$(ExecName, LastBackslashPos + 1) |
|
|
|
 |
|
 |
|
|
1 Refer to Appendix B, "Frequently Asked Questions," for further resources if you wish to learn more about module handles. |
|
|
|
|
|